package br.com.werp.suporte.Intranet;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.egen.util.jdbc.*;
import com.egen.util.text.*;

/**
 * Creation Date 05/09/2005 12:30:10
 * Last Modify Date 12/07/2006 14:52:39
 */

public class AvisosAction extends com.egen.util.struts.AbstractAction {

  public ActionForward perform_salvar_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //-----------------------------------------------------------------
      br.com.werp.regras.geral.Rh rh =
        br.com.werp.regras.geral.FabricaSubSistema.getRh();
      String usuario = (String) session.getAttribute("j_username");
      rh.inserirNoticia(form, usuario);

      AvisosActionForm f = (AvisosActionForm) form;

      if (!f.getFlag().equals("TRUE")) {
        request.setAttribute("noti_id",rh.pesquisarNoticiaID());
        actionForward = mapping.findForward("same");
      } else {
        actionForward = mapping.findForward("pesquisar");
      }
      //-----------------------------------------------------------------

    }
    catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              (e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_excluir_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //-------------------------------------------------------------------------
      br.com.werp.regras.geral.Rh rh =
        br.com.werp.regras.geral.FabricaSubSistema.getRh();
      String usuario = (String) session.getAttribute("j_username");
      rh.excluirNoticia(form, usuario);
      //-------------------------------------------------------------------------

      actionForward = mapping.findForward("pesquisar");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              (e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_resetfull_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //-----------------------------------------------------
      form.reset(null, null);
      //-----------------------------------------------------
      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              (e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_carregar_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //--------------------------------------------------------------------------
      br.com.werp.regras.geral.Rh rh =
        br.com.werp.regras.geral.FabricaSubSistema.getRh();

      rh.carregarNoticia(form);

      //--------------------------------------------------------------------------

      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              (e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

}
